package day01;

import java.util.Arrays;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/2/28 10:43
 */
public class InsertSortRecursion {
    public static void main(String[] args) {
        int[] arr = {1, 3, 2, 5, 4, 8};
        sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void sort(int[] arr) {
        insertRecursion(arr, 1);
    }

    public static void insertRecursion(int[] arr, int low) {
        if (low == arr.length) {
            return;
        }
        int t = arr[low];
        int i = low - 1;
        while(i >= 0 && arr[i] > t) {
            arr[i+1] = arr[i];
            i--;
        }
        if (i+1 != low) {
            arr[i+1] = t;
        }
        insertRecursion(arr, low+1);
    }


}
